import Vue from 'vue'
import App from './App'
// 引入全局存储
import store from './store'
// 引入全局配置
import $mAssetsPath from '@/config/assets.config.js';
import $mConfig from '@/config/global.config.js';
import commonMixin from '@/common/commonMixin'

// 引入全局方法
import {
	http
} from '@/common/request';
import $mUtil from '@/common/util.js';
// 全局组件
import navbar from '@/components/hx-navbar/hx-navbar.nvue';
import ldLoading from '@/components/ld-loading/index.vue';
import nodata from '@/components/noData/nodata.vue';
import loadMore from '@/components/uni-load-more/uni-load-more.vue';
import Directives from './directives/index.js';
import welfareGoods from '@/components/welfare-goods/index.vue';
import donationNews from '@/components/donation-news/index.vue';

// 客服
import VueCompositionAPI from "@vue/composition-api";
Vue.use(VueCompositionAPI);
// import entrepreneurshipZoneTabbar from '@/components/entrepreneurship-zone-tabbar/index.vue';



// 网络状态监听
// uni.getNetworkType({
// 	success: res => {
// 		console.log(res)
// 		store.dispatch('networkStateChange', res.networkType);
// 	}
// });
// uni.onNetworkStatusChange(function (res) {
// 	console.log(res+'onNetworkStatusChange')
// 	store.dispatch('networkStateChange', res.networkType);
// });

if (process.env.NODE_ENV === 'production') {
	Vue.config.productionTip = false;
}
// 挂载全局自定义方法
Vue.prototype.$store = store
Vue.prototype.$adpid = ""

Vue.prototype.$http = http;
Vue.prototype.$mConfig = $mConfig;
Vue.prototype.$mAssetsPath = $mAssetsPath;
Vue.prototype.$mUtil = $mUtil;
Vue.component('navbar', navbar);
Vue.component('ldLoading', ldLoading);
Vue.component('nodata', nodata);
Vue.component('loadMore', loadMore);
Vue.component('welfareGoods', welfareGoods);
Vue.component('donationNews', donationNews);
// Vue.component('entrepreneurshipZoneTabbar', entrepreneurshipZoneTabbar);
App.mpType = 'app'

Vue.use(Directives);
// 保留小数点后两位
Vue.filter('keepTwo', value => {
	return (Math.floor((value || 0) * 100) / 100).toFixed(2);
});

// 整数，获取数字整数部分
Vue.filter('integer', value => {
	if (value) {
		return Math.trunc(value)
	};
	return 0
});
// 整数，获取数字整数部分
Vue.filter('integer', value => {
	if (value) {
		return Math.trunc(value)
	};
	return 0
});
// 整数，获取数字整数部分
Vue.filter('decimals', value => {
	if (value) {
		try {
			value += "";
			return value.split('.')[1] || '00'
		} catch {
			return "00"
		}
	};
	return '00'
});

// integral(){

// 	integral(num) {
// 		//判断数字是否有小数 

// 	}
// }

// 添加小数
Vue.prototype.$addDecimals = (num = 0, length = 8, type = true) => {
	// length 小数的长度，type 是否需要处理
	try{
		if (!type) {
			return num
		}
		num += '';
		if (num.indexOf('.') === -1) {
			num = `${num}.`
			for(let i = 1 ; i <= length; i++){
				num += '0';
			}
			return num
		}
		
		const numArr = num.split('.');
		
		let integerNum = numArr[0],
			decimals = numArr[1];
		
		if (decimals.length === length) {
			return num
		}
		const addLength = length - decimals.length;
		for (let i = 1; i <= addLength > 0 ? addLength : 0; i++) {
			decimals += '0'
		}
		return `${integerNum}.${decimals}`
	}catch(err){
		return num
	}
}

// import Vue from 'vue'
/**
 * 注册指令
 */

//引入 u-view 1.x
import uView from 'uview-ui'
Vue.use(uView)

//全局组件混入mixin
Vue.use(commonMixin);

const app = new Vue({
	store,
	...App
})
app.$mount()
